package com.thrd.taiexhibition.model;

import com.alibaba.fastjson.JSON;
import com.thrd.basicframework.http.OkHttpUtils;
import com.thrd.basicframework.http.callback.ThrdCallBack;
import com.thrd.taiexhibition.bean.BeanStoryType;
import com.thrd.taiexhibition.callback.MvpCallback;
import com.thrd.taiexhibition.utils.Constant;

import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/3/22
 */
public class CityStoryModel {
    public static final String TAG="CityStoryModel";


    /**
     * 获取城市首页
     */
    public void getCityStory(String id,final MvpCallback<List<BeanStoryType>> mvpCallback){
        OkHttpUtils.get().url(Constant.HTTP_CITY_STORY)
                .tag(TAG)
                .addParams("cityId",id)
                .build().execute(new ThrdCallBack< List<BeanStoryType>>() {
            @Override
            public void onFailed(String e, int code) {
                mvpCallback.onFailed(e,code);
            }

            @Override
            public void onResponse( List<BeanStoryType> response, int id) {
                mvpCallback.onSuccess(response);
            }

            @Override
            public  List<BeanStoryType> onJson(String s) {
//                List<BeanStoryTypeList> lis =JSON.parseArray(s);
//                Map<String, Object> map=object.getInnerMap();
//                List<BeanStoryType>  beanStoryTypeList=new ArrayList<>();
//                for (Map.Entry<String, Object> entry : map.entrySet()) {
//                    BeanStoryType beanStoryType=new BeanStoryType();
//                    beanStoryType.setStoryList(JSON.parseArray(entry.getValue().toString(),BeanStory.class));
//                    beanStoryType.setType(entry.getKey());
//                    beanStoryTypeList.add(beanStoryType);
//                }






                //  =JSON.parseObject(s);
                //  Map<String,BeanStory> map = (Map<String, BeanStory>) JSONObject.parse(s);
                return JSON.parseArray(s,BeanStoryType.class);
            }


        });
//        String data="{\n" +
//                "        \"00\":[\n" +
//                "            {\n" +
//                "                \"id\":1,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"1\",\n" +
//                "                \"storyintro\":\"1\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"1\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:20:10\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"id\":2,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"2\",\n" +
//                "                \"storyintro\":\"2\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"2\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:20:15\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"id\":3,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"3\",\n" +
//                "                \"storyintro\":\"3\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"3\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:20:32\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"id\":4,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"4\",\n" +
//                "                \"storyintro\":\"4\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"4\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:21:05\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"id\":5,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"5\",\n" +
//                "                \"storyintro\":\"5\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"5\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:21:10\"\n" +
//                "            }\n" +
//                "        ],\n" +
//                "        \"01\":[\n" +
//                "            {\n" +
//                "                \"id\":8,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"8\",\n" +
//                "                \"storyintro\":\"8\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"8\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:21:47\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"id\":7,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"7\",\n" +
//                "                \"storyintro\":\"7\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"7\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:21:24\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"id\":6,\n" +
//                "                \"cityid\":1,\n" +
//                "                \"storytitle\":\"6\",\n" +
//                "                \"storyintro\":\"6\",\n" +
//                "                \"storycoverimg\":\"company/companyAppletQrCode/companyAppletQrCode1.jpg\",\n" +
//                "                \"storytitletype\":\"6\",\n" +
//                "                \"storyskiptype\":\"0\",\n" +
//                "                \"onerelevanceid\":1,\n" +
//                "                \"tworelevanceid\":0,\n" +
//                "                \"threerelevanceid\":0,\n" +
//                "                \"createtime\":\"2021-03-22 14:21:18\"\n" +
//                "            }\n" +
//                "        ]\n" +
//                "    }";
//
//        JSONObject object =JSON.parseObject(data);
//        Map<String, Object> map=object.getInnerMap();
//        List<BeanStoryType>  beanStoryTypeList=new ArrayList<>();
//        for (Map.Entry<String, Object> entry : map.entrySet()) {
//            BeanStoryType beanStoryType=new BeanStoryType();
//
//            beanStoryType.setStoryList(JSON.parseArray(entry.getValue().toString(),BeanStory.class));
//            beanStoryType.setType(entry.getKey());
//            beanStoryTypeList.add(beanStoryType);
//        }
//        mvpCallback.onSuccess(beanStoryTypeList);

    }
}
